package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniVideo;
import com.ruoyi.applet.service.IMiniVideoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频管理Controller
 *
 * @author liucan
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/applet/video")
public class MiniVideoController extends BaseController {
    @Resource
    private IMiniVideoService miniVideoService;

    @Resource
    private MiniLeagueController miniLeagueController;

    /**
     * 查询视频管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniVideo miniVideo, HttpServletRequest request) {
        startPage();
        miniVideo.setToApplet(miniLeagueController.toApplet(request));
        List<MiniVideo> list = miniVideoService.selectMiniVideoList(miniVideo);
        return getDataTable(list,null);
    }

    /**
     * 新增视频管理
     */
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniVideo miniVideo, HttpServletRequest request) {
        miniVideo.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniVideoService.insertMiniVideo(miniVideo));
    }

    /**
     * 修改视频管理
     */
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniVideo miniVideo, HttpServletRequest request) {
        miniVideo.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniVideoService.updateMiniVideo(miniVideo));
    }

    /**
     * 删除视频管理
     */
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniVideoService.deleteMiniVideoByIds(ids));
    }

    /**
     * 播放视频
     */
    @GetMapping("/play")
    public AjaxResult play(String id) {
        return toAjax(miniVideoService.play(id));
    }



    /**
     * 导出视频管理列表
     */
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniVideo miniVideo) {
        List<MiniVideo> list = miniVideoService.selectMiniVideoList(miniVideo);
        ExcelUtil<MiniVideo> util = new ExcelUtil<MiniVideo>(MiniVideo.class);
        util.exportExcel(response, list, "视频管理数据");
    }

    /**
     * 获取视频管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniVideoService.selectMiniVideoById(id));
    }

}
